package function;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @Author Klys
 * @Date 2023/6/19 17:03
 * @Description
 * @Version 1.0
 */
public class Main {

    public static void main(String[] args) {

        Stream<String> stream = Stream.of("This", "is", "a", "test");
        Map<String, Integer> map = stream.collect(Collectors.toMap(Function.identity(), String::length));
        System.out.println(map);

        List<String> list = Arrays.asList("a", "b", "c");
        Map<String, String> collect = list
                .stream()
                .collect(Collectors.toMap(    //两个参数toMap
                        Function.identity(), // <-- And this,
                        str -> str + "_test"));// <-- is the same as this.
        System.out.println(collect);


        List<String> myList = Arrays.asList("a", "a", "a", "b", "c");
        Map<String, String> myCollect = myList
                .stream()
                .collect(Collectors.toMap(     //三个参数toMap
                        obj -> obj + "_toMap",
                        Function.identity(),
                        (a, b) -> {
                            String s = a + b;
                            return s;
                        }));
        System.out.println(myCollect);
    }
}

/*
 *
 * (a,b)->a+b
 * (a+b,c)->a+b+c
 *
 *
 * @Author Klys
 * @Description //TODO
 * @Date
 * @Param
 * @return
 */

